{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "empty_list: list[int] = []\n",
    "print(any(empty_list))  # Output: False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mixed_values: list[str | int | list[int] | None] = [0, \"\", [], 5, None]\n",
    "print(any(mixed_values))  # 5 is truthy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "non_empty_string = \"hello\"\n",
    "empty_string = \"\"\n",
    "\n",
    "print(f\"non_empty_string is {any(non_empty_string)}\")  # all characters are truthy\n",
    "print(f\"empty_string is {any(empty_string)}\")  # empty iterable"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "numbers = [-1, 0, -3, 4, -5]\n",
    "print(any(x > 0 for x in numbers))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def infinite_sequence():\n",
    "    i = 0\n",
    "    while True:\n",
    "        i += 1\n",
    "        yield i\n",
    "\n",
    "\n",
    "# `any()` stops after finding the first truthy value\n",
    "# This will run forever, because all values are positive\n",
    "print(any(x < -1 for x in infinite_sequence()))\n",
    "\n",
    "print(any(x > 10 for x in infinite_sequence()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def infinite_sequence():\n",
    "    i = 0\n",
    "    while True:\n",
    "        i += 1\n",
    "        yield i\n",
    "\n",
    "\n",
    "# `any()` stops after finding the first truthy value\n",
    "print(any(x > 10 for x in infinite_sequence()))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
